/*
** serv.c for  in /u/all/caille_c/cu/minitalk/server
** 
** Made by carole cailleux
** Login   <caille_c@epitech.net>
** 
** Started on  Wed Feb 24 12:37:05 2010 carole cailleux
** Last update Wed Mar 17 18:23:55 2010 carole cailleux
*/

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include "serv.h"

int		gl_pid_cl = 0;

void		cmpt()
{
  while (1)
    pause();
}

void		handle_sig(int sig)
{
  static int	val;
  static int	i;

  signal(SIGUSR1, handle_sig);
  signal(SIGUSR2, handle_sig);
  calc_octet(sig, i, &val);
  i++;
  if (i == 32)
    calc_pid(&val);
  else if (i % 8 == 0 && i > 32)
    calc_chara(&val, &i);
  if (gl_pid_cl && i > 32)
    kill(gl_pid_cl, SIGUSR1);
}

int		main(void)
{
  signal(SIGUSR1, handle_sig);
  signal(SIGUSR2, handle_sig);
  my_putstr("pid serv = ");
  my_put_nbr(getpid());
  my_putchar('\n');
  cmpt();
  return (0);
}
